package org.dromara.wms.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.web.core.BaseService;
import org.dromara.wms.domain.WmsStockCheck;
import org.dromara.wms.service.WmsStockCheckService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.wms.domain.WmsStock;
import org.dromara.wms.service.WmsStockService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 库存数量
 *
 * @author wenrui Su
 * @date 2024-05-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/stock")
public class WmsStockController extends BaseService {

  private final WmsStockService wmsStockService;
  private final WmsStockCheckService wmsStockCheckService;

/**
 * 查询库存数量列表
 */
@SaCheckPermission("wms:stock:list")
@GetMapping("/list")
  public TableDataInfo<WmsStock> list(WmsStock bo, PageQuery pageQuery) {
    return wmsStockService.queryPageList(bo, pageQuery);
  }

  /**
   * 导出库存数量列表
   */
  @SaCheckPermission("wms:stock:export")
  @Log(title = "库存数量", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(WmsStock bo, HttpServletResponse response) {
    List<WmsStock> list = wmsStockService.queryList(bo);
    ExcelUtil.exportExcel(list, "库存数量", WmsStock. class,response);
  }

  /**
   * 获取库存数量详细信息
   *
   * @param id 主键
   */
  @SaCheckPermission("wms:stock:query")
  @GetMapping("/{id}")
  public R<WmsStock> getInfo(@NotNull(message = "主键不能为空")  @PathVariable Long id) {
    return R.ok(wmsStockService.queryById(id));
  }


  /**
   * 库存盘点 发送
   */
  @SaCheckPermission("wms:stockCheck:send")
  @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping("/send")
  public R<Void> send(@Validated(EditGroup.class) @RequestBody WmsStockCheck bo) {
    return toAjax(wmsStockCheckService.sendUpdate(bo));
  }
  /**
   * 库存盘点 执行
   */
  @SaCheckPermission("wms:stockCheck:setStock")
  @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping("/setStock")
  public R<Void> setStock(@Validated(EditGroup.class) @RequestBody WmsStockCheck bo) {
    return toAjax(wmsStockCheckService.setUpdateByBo(bo));
  }


  /**
   * 新增库存数量
  @SaCheckPermission("wms:stock:add")
  @Log(title = "库存数量", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsStock bo) {
    return toAjax(wmsStockService.insertByBo(bo));
  }
   */

  /**
   * 修改库存数量
  @SaCheckPermission("wms:stock:edit")
  @Log(title = "库存数量", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsStock bo) {
    return toAjax(wmsStockService.updateByBo(bo));
  }
   */

  /**
   * 删除库存数量
   *
   * @param ids 主键串
  @SaCheckPermission("wms:stock:remove")
  @Log(title = "库存数量", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
    return toAjax(wmsStockService.deleteWithValidByIds(List.of(ids), true));
  }
   */
}
